import { planDetail, planList, forecast, forcastDetail } from '@/mock/plan';
// import { Message } from 'element-ui';

import axios from 'poros/http';

// const BASE_API = 'http://10.110.96.153:8030';
const BASE_API = '';

//M9,M3的tableList接口
export const postLoadTableList = data =>
  // new Promise(resolve => resolve(forecast));
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/listByPage`,
    method: 'post',
    data,
  });

//M9,M3发起预测接口1
export const postForecast = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/process/saveOrUpdate`,
    method: 'post',
    data,
  });

//M9,M3的发起预测接口2
export const postForecastData = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/save`,
    method: 'post',
    data,
  });

// 删除计划
export const postDeleteMforecast = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/delete`,
    method: 'post',
    data,
  });

// 获取详情
export const getMforecastDetail = id =>
  // new Promise(resolve => resolve(forcastDetail));
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/query/${id}`,
    method: 'get',
  });

//查询操作日志
export const getOperationLog = (type, id) =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/log/query/${type}/${id}`,
    method: 'get',
  });

// 分组录入 提交
export const postPlanGroupRecord = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/groupEntry`,
    method: 'post',
    data,
  });

// 部长审批
export const postMinisterApprove = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/ministerApprove`,
    method: 'post',
    data,
  });

// Kapm总监 审批
export const postKapmDirectorApprove = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/kapmDirectorApprove`,
    method: 'post',
    data,
  });

// 销售总监 审批
export const postSaleDirectorApprove = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/saleDirectorApprove`,
    method: 'post',
    data,
  });

// 录入预分配
export const postEntryPreAllocation = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/entryPreAllocation`,
    method: 'post',
    data,
  });

// /groupEntryForecast 分组录入销量预测
export const postGroupEntryForecast = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast//groupEntryForecast`,
    method: 'post',
    data,
  });

// 分组审批2
export const postSalesApproveSecondary = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/salesApprove`,
    method: 'post',
    data,
  });

// 销售总监审批2
export const postSaleDirectorApprove2 = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/saleDirectorApprove2`,
    method: 'post',
    data,
  });

// 复用录入明细
export const postReuseDetailList = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/reuse`,
    method: 'post',
    data,
  });

// 导出预分配模板
export const postExportDetailTemplate = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/downExcelImportTemplate`,
    method: 'post',
    responseType: 'arraybuffer',
    hasInterceptors: true,
    data,
  });

// m3 供应计划录入
export const postEntrySupplyPlan = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/entrySupplyPlan`,
    method: 'post',
    data,
  });

// 导出
export const postExportDetail = data => {
  // console.log('data: ', data);
  // const fcst = [1, 4];
  // if (!fcst.includes(data.templateType)) {
  //   Message.error('该功能暂未实现！');
  //   return Promise.reject('该功能暂未实现！');
  // }
  return axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/downExcelDetail`,
    method: 'post',
    responseType: 'arraybuffer',
    hasInterceptors: true,
    data,
  });
};

// 导入数据
export const postUploadFile = (file, id, type) => {
  const formData = new FormData();
  formData.append('file', file);
  return axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/importExcel/${id}/${type}`,
    headers: { 'Content-Type': 'nultipart/form-data' },
    method: 'post',
    data: formData,
  });
};

// 转他人处理接口
export const postReuseDetail = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecast/forward`,
    method: 'post',
    data,
  });

// 获取RP关系列表
export const getRpRelationList = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecastDetail/listByPage`,
    method: 'post',
    data,
  });

// 获取BP关系列表
export const getBpRelationList = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecastDetail/listByPage`,
    method: 'post',
    data,
  });

// 获取M9关系列表
export const getM9RelationList = data =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecastDetail/listMforecast`,
    method: 'post',
    data,
  });

// 比较版本
export const getLastFcst = (params, data) =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecastDetail/differenceContrast`,
    method: 'post',
    data,
    params,
  });

// 获取上一版本信息
export const getLastDetailInfo = params =>
  axios({
    url: `${BASE_API}/api/salesforecast-service/mforecastDetail/previous`,
    method: 'get',
    params,
  });
